﻿* Encoding: UTF-8.
SET seed=42616.

* This generates the random outcomes for each of the states based on the latest forecast and SEyx, and runs 100,000 scenarios.

INPUT PROGRAM .
+ LOOP id = 1 to 100000 .
+   COMPUTE Alabama = 35.261766 + RV.NORMAL( 0 , 3.0785402   ) .
+   COMPUTE Alaska = 43.041334 + RV.NORMAL( 0 , 3.0785402   ) .
+   COMPUTE Arizona = 48.552132 + RV.NORMAL( 0 , 3.0785402   ) .
+   COMPUTE Arkansas = 33.938589 + RV.NORMAL( 0 , 3.0785402   ) .
+   COMPUTE California = 63.675035 + RV.NORMAL( 0 , 3.0785402   ) .
+   COMPUTE Colorado = 55.448905 + RV.NORMAL( 0 , 3.0785402   ) .
+   COMPUTE Connecticut = 58.738030 + RV.NORMAL( 0 , 3.0785402   ) .
+   COMPUTE DC = 93.615526 + RV.NORMAL( 0 , 3.0785402   ) .
+   COMPUTE Delaware = 58.738030 + RV.NORMAL( 0 , 3.0785402   ) .
+   COMPUTE Florida = 44.235107 + RV.NORMAL( 0 , 3.0785402   ) .
+   COMPUTE Georgia =48.513992 + RV.NORMAL( 0 , 3.0785402   ) .
+   COMPUTE Hawaii = 63.680854 + RV.NORMAL( 0 , 3.0785402   ) .
+   COMPUTE Idaho = 32.245580 + RV.NORMAL( 0 , 3.0785402   ) .
+   COMPUTE Illinois =57.198882 + RV.NORMAL( 0 , 3.0785402   ) .
+   COMPUTE Indiana = 40.058270 + RV.NORMAL( 0 , 3.0785402   ) .
+   COMPUTE Iowa = 44.138256 + RV.NORMAL( 0 , 3.0785402   ) .
+   COMPUTE Kansas = 40.771818 + RV.NORMAL( 0 , 3.0785402   ) .
+   COMPUTE Kentucky = 34.968129 + RV.NORMAL( 0 , 3.0785402   ) .
+   COMPUTE Louisiana = 38.767298 + RV.NORMAL( 0 , 3.0785402   ) .
+   COMPUTE Maine = 53.142436 + RV.NORMAL( 0 , 3.0785402   ) .
+   COMPUTE Maryland = 65.711175 + RV.NORMAL( 0 , 3.0785402   ) .
+   COMPUTE Massachusetts = 65.799148 + RV.NORMAL( 0 , 3.0785402   ) .
+   COMPUTE Michigan = 49.830224 + RV.NORMAL( 0 , 3.0785402   ) .
+   COMPUTE Minnesota = 52.094020+ RV.NORMAL( 0 , 3.0785402   ) .
+   COMPUTE Mississippi = 39.865104 + RV.NORMAL( 0 , 3.0785402   ) .
+   COMPUTE Missouri = 40.423605 + RV.NORMAL( 0 , 3.0785402   ) .
+   COMPUTE Montana = 39.852702 + RV.NORMAL( 0 , 3.0785402   ) .
+   COMPUTE Nebraska = 38.442253 + RV.NORMAL( 0 , 3.0785402   ) .
+   COMPUTE Nevada = 49.636544 + RV.NORMAL( 0 , 3.0785402   ) .
+   COMPUTE NewHampshire = 52.204704 + RV.NORMAL( 0 , 3.0785402   ) .
+   COMPUTE NewJersey = 56.601130 + RV.NORMAL( 0 , 3.0785402   ) .
+   COMPUTE NewMexico = 54.004939 + RV.NORMAL( 0 , 3.0785402   ) .
+   COMPUTE NewYork = 62.862655 + RV.NORMAL( 0 , 3.0785402   ) .
+   COMPUTE NorthCarolina = 47.696802 + RV.NORMAL( 0 , 3.0785402   ) .
+   COMPUTE NorthDakota = 30.882530 + RV.NORMAL( 0 , 3.0785402   ) .
+   COMPUTE Ohio = 44.246633 + RV.NORMAL( 0 , 3.0785402   ) .
+   COMPUTE Oklahoma = 31.164614 + RV.NORMAL( 0 , 3.0785402   ) .
+   COMPUTE Oregon = 56.841013 + RV.NORMAL( 0 , 3.0785402   ) .
+   COMPUTE Pennsylvania = 48.991856 + RV.NORMAL( 0 , 3.0785402   ) .
+   COMPUTE RhodeIsland = 59.172183 + RV.NORMAL( 0 , 3.0785402   ) .
+   COMPUTE SouthCarolina = 42.245235 + RV.NORMAL( 0 , 3.0785402   ) .
+   COMPUTE SouthDakota = 34.729463 + RV.NORMAL( 0 , 3.0785402   ) .
+   COMPUTE Tennessee = 36.363792 + RV.NORMAL( 0 , 3.0785402   ) .
+   COMPUTE Texas = 45.513791 + RV.NORMAL( 0 , 3.0785402   ) .
+   COMPUTE Utah = 37.517238 + RV.NORMAL( 0 , 3.0785402   ) .
+   COMPUTE Vermont = 67.031001 + RV.NORMAL( 0 , 3.0785402   ) .
+   COMPUTE Virginia = 53.634951 + RV.NORMAL( 0 , 3.0785402   ) .
+   COMPUTE Washington = 58.486871 + RV.NORMAL( 0 , 3.0785402   ) .
+   COMPUTE WestVirginia = 28.257527 + RV.NORMAL( 0 , 3.0785402   ) .
+   COMPUTE Wisconsin = 48.717121 + RV.NORMAL( 0 , 3.0785402   ) .
+   COMPUTE Wyoming = 25.654035 + RV.NORMAL( 0 , 3.0785402   ) .
+   END CASE .
+ END LOOP .
+ END FILE .
END INPUT PROGRAM .

EXECUTE.

 * This next section weights each of the random state outcomes using the turnout weight so they can be aggregated to a national popular vote estimate: TotalPV .

COMPUTE AlabamaWTD = Alabama *.01473313 .
COMPUTE AlaskaWTD = Alaska * .00221068 . 
COMPUTE ArizonaWTD = Arizona * .02144136 .
COMPUTE ArkansasWTD = Arkansas * .00761856 .
COMPUTE CaliforniaWTD = California * .11008507 . 
COMPUTE ColoradoWTD = Colorado *.02038100 .
COMPUTE ConnecticutWTD = Connecticut * .01155070 . 
COMPUTE DCWTD = DC * .00216038 . 
COMPUTE DelawareWTD = Delaware * .00319560 . 
COMPUTE FloridaWTD = Florida * .07052584 . 
COMPUTE GeorgiaWTD = Georgia * .03174234 . 
COMPUTE HawaiiWTD = Hawaii * .00362087 .
COMPUTE IdahoWTD = Idaho * .00540975 .
COMPUTE IllinoisWTD = Illinois * .03806651 .
COMPUTE IndianaWTD = Indiana * .01911385 .
COMPUTE IowaWTD = Iowa * .01065520 .
COMPUTE KansasWTD = Kansas * .00862926 .
COMPUTE KentuckyWTD = Kentucky * .01350039.
COMPUTE LouisianaWTD = Louisiana * .01358200 .
COMPUTE MaineWTD = Maine * .00511821 .
COMPUTE MarylandWTD = Maryland * .01904633 .
COMPUTE MassachusettsWTD = Massachusetts * .02282782 .
COMPUTE MichiganWTD = Michigan * .03507643 .
COMPUTE MinnesotaWTD = Minnesota * .02058799 .
COMPUTE MississippiWTD = Mississippi * .00833620 .
COMPUTE MissouriWTD = Missouri * .01911266 .
COMPUTE MontanaWTD = Montana * .00378419 .
COMPUTE NebraskaWTD = Nebraska * .00599044 .
COMPUTE NevadaWTD = Nevada * .00883280 .
COMPUTE NewHampshireWTD = NewHampshire * .00508454 .
COMPUTE NewJerseyWTD = NewJersey * .02888756 .
COMPUTE NewMexicoWTD = NewMexico * .00581087 .
COMPUTE NewYorkWTD = NewYork * .05451158 .
COMPUTE NorthCarolinaWTD = NorthCarolina * .03500681 .
COMPUTE NorthDakotaWTD = NorthDakota * .00225420 .
COMPUTE OhioWTD = Ohio * .03752107 .
COMPUTE OklahomaWTD = Oklahoma * .00980262 .
COMPUTE OregonWTD = Oregon * .01478482 .
COMPUTE PennsylvaniaWTD = Pennsylvania * .04396477 .
COMPUTE RhodeIslandWTD = RhodeIsland * .00326337 .
COMPUTE SouthCarolinaWTD = SouthCarolina * .01592841 .
COMPUTE SouthDakotaWTD = SouthDakota * .00264663 .
COMPUTE TennesseeWTD = Tennessee * .01926982 .
COMPUTE TexasWTD = Texas * .07170728 .
COMPUTE UtahWTD = Utah * .00916753 .
COMPUTE VermontWTD = Vermont * .00228654 .
COMPUTE VirginiaWTD = Virginia * .02814401 .
COMPUTE WashingtonWTD = Washington * .02543165 .
COMPUTE WestVirginiaWTD = WestVirginia * .00502532 .
COMPUTE WisconsinWTD = Wisconsin * .02084465 .
COMPUTE WyomingWTD = Wyoming * .00172041 .
EXECUTE.

COMPUTE TotalPV= SUM(AlabamaWTD to WyomingWTD) .
EXECUTE.

* Recoding the popular vote outcomes to Win/Lose dicotomy

RECODE Alabama Alaska Arizona Arkansas California Colorado Connecticut DC Delaware Florida Georgia 
    Hawaii Idaho Illinois Indiana Iowa Kansas Kentucky Louisiana Maine Maryland Massachusetts Michigan 
    Minnesota Mississippi Missouri Montana Nebraska Nevada NewHampshire NewJersey NewMexico NewYork 
    NorthCarolina NorthDakota Ohio Oklahoma Oregon Pennsylvania RhodeIsland SouthCarolina SouthDakota 
    Tennessee Texas Utah Vermont Virginia Washington WestVirginia Wisconsin Wyoming (Lowest thru 
    49.999999999999999=0) (50.00000000000000001 thru Highest=1) INTO AlabamaWin AlaskaWin ArizonaWin 
    ArkansasWin CaliforniaWin ColoradoWin ConnecticutWin DCWin DelawareWin FloridaWin GeorgiaWin 
    HawaiiWin IdahoWin IllinoisWin IndianaWin IowaWin KansasWin KentuckyWin LouisianaWin MaineWin 
    MarylandWin MassachusettsWin MichiganWin MinnesotaWin MississippiWin MissouriWin MontanaWin 
    NebraskaWin NevadaWin NewHampshireWin NewJerseyWin NewMexicoWin NewYorkWin NorthCarolinaWin 
    NorthDakotaWin OhioWin OklahomaWin OregonWin PennsylvaniaWin RhodeIslandWin SouthCarolinaWin 
    SouthDakotaWin TennesseeWin TexasWin UtahWin VermontWin VirginiaWin WashingtonWin WestVirginiaWin 
    WisconsinWin WyomingWin.
EXECUTE.


* Weighting the Win/Lose dichotomy by the electoral votes in each state to generate an aggregated electoral vote total .

COMPUTE AlabamaEC = AlabamaWin * 9 .
COMPUTE AlaskaEC = AlaskaWin * 3 . 
COMPUTE ArizonaEC = ArizonaWin * 11 .
COMPUTE ArkansasEC = ArkansasWin * 6 .
COMPUTE CaliforniaEC = CaliforniaWin * 54 . 
COMPUTE ColoradoEC = ColoradoWin * 10 .
COMPUTE ConnecticutEC = ConnecticutWin * 7 . 
COMPUTE DCEC = DCWin * 3 . 
COMPUTE DelawareEC = DelawareWin * 3 . 
COMPUTE FloridaEC = FloridaWin * 30 . 
COMPUTE GeorgiaEC = GeorgiaWin * 16 . 
COMPUTE HawaiiEC = HawaiiWin * 4 .
COMPUTE IdahoEC = IdahoWin * 4 .
COMPUTE IllinoisEC = IllinoisWin * 19 .
COMPUTE IndianaEC = IndianaWin * 11 .
COMPUTE IowaEC = IowaWin * 6 .
COMPUTE KansasEC = KansasWin * 6 .
COMPUTE KentuckyEC = KentuckyWin * 8 .
COMPUTE LouisianaEC = LouisianaWin * 8 .
COMPUTE MaineEC = MaineWin * 4 .
COMPUTE MarylandEC = MarylandWin * 10 .
COMPUTE MassachusettsEC = MassachusettsWin * 11 .
COMPUTE MichiganEC = MichiganWin * 15 .
COMPUTE MinnesotaEC = MinnesotaWin * 10 .
COMPUTE MississippiEC = MississippiWin * 6 .
COMPUTE MissouriEC = MissouriWin * 10 .
COMPUTE MontanaEC = MontanaWin * 4 .
COMPUTE NebraskaEC = NebraskaWin * 5 .
COMPUTE NevadaEC = NevadaWin * 6 .
COMPUTE NewHampshireEC = NewHampshireWin * 4 .
COMPUTE NewJerseyEC = NewJerseyWin * 14 .
COMPUTE NewMexicoEC = NewMexicoWin * 5 .
COMPUTE NewYorkEC = NewYorkWin * 28 .
COMPUTE NorthCarolinaEC = NorthCarolinaWin * 16 .
COMPUTE NorthDakotaEC = NorthDakotaWin * 3 .
COMPUTE OhioEC = OhioWin * 17 .
COMPUTE OklahomaEC = OklahomaWin * 7 .
COMPUTE OregonEC = OregonWin * 8 .
COMPUTE PennsylvaniaEC = PennsylvaniaWin * 19 .
COMPUTE RhodeIslandEC = RhodeIslandWin * 4 .
COMPUTE SouthCarolinaEC = SouthCarolinaWin * 9 .
COMPUTE SouthDakotaEC = SouthDakotaWin * 3 .
COMPUTE TennesseeEC = TennesseeWin * 11 .
COMPUTE TexasEC = TexasWin * 40 .
COMPUTE UtahEC = UtahWin * 6 .
COMPUTE VermontEC = VermontWin * 3 .
COMPUTE VirginiaEC = VirginiaWin * 13 .
COMPUTE WashingtonEC = WashingtonWin * 12 .
COMPUTE WestVirginiaEC = WestVirginiaWin * 4 .
COMPUTE WisconsinEC = WisconsinWin * 10 .
COMPUTE WyomingEC = WyomingWin * 3 .
EXECUTE.

COMPUTE TotalECV = SUM(AlabamaEC to WyomingEC) .
EXECUTE.

FORMATS TotalECV (F8.0).
EXECUTE.

* Recoding the Total Popular Vote and Electoral Vote aggregations into a simple Win/Lose dichotomy . 

RECODE TotalPV (Lowest thru 49.99999999=0) (50.000000000001 thru Highest=1) INTO PVWin.
EXECUTE.

RECODE TotalECV (Lowest thru 268=0) (269=1) (270 thru Highest=2) INTO ECVWin.
EXECUTE.


FREQUENCIES VARIABLES=TotalPV
  /STATISTICS=MEAN MEDIAN MODE MINIMUM MAXIMUM STDDEV
 /FORMAT=NOTABLE
  /PERCENTILES .5 2.5 97.5 99.5
  /HISTOGRAM
   /ORDER=ANALYSIS.

FREQUENCIES VARIABLES=TotalECV
  /STATISTICS=MEAN MEDIAN MODE MINIMUM MAXIMUM STDDEV
  /PERCENTILES .5 2.5 97.5 99.5
  /HISTOGRAM
  /ORDER=ANALYSIS.

CROSSTABS
  /TABLES=PVWin BY ECVWin
  /FORMAT=AVALUE TABLES
  /CELLS=COUNT TOTAL 
  /COUNT ROUND CELL.











